/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
public class leetcode21{
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        List<Integer>list=new ArrayList<>();
        while (list1!=null){
            list.add(list1.val);
            list1=list1.next;
        }
        while (list2!=null){
            list.add(list2.val);
            list2=list2.next;
        }
        Collections.sort(list);
        ListNode vo=new ListNode();
        ListNode nextVo=vo;
        for(Integer val:list){
            nextVo.next=new ListNode(val);
            nextVo=nextVo.next;
        }
        return vo.next;

    }
}